package com.huang.CAS;

import java.util.concurrent.atomic.AtomicStampedReference;

public class AtomicStamp {
   static volatile int stampe=1;
    public static void main(String[] args) {
        AtomicStampedReference<Integer> stampedReference = new AtomicStampedReference<Integer>(1,stampe);

        new Thread(()->{
                if(stampedReference.compareAndSet(1,666,stampe,stampe+1)){
                    System.out.println("1修改成功了。。。stampe从"+stampe+"改到"+stampedReference.getStamp());
                }else{
                    System.out.println("1修改失败stampe为"+stampe);
                }

        }).start();

        new Thread(()->{
            if(stampedReference.compareAndSet(1,666,stampe,stampe+1)){
                System.out.println("2修改成功了。。。stampe从"+stampe+"改到"+stampedReference.getStamp());
            }else{
                System.out.println("2修改失败stampe为"+stampe);
            }

        }).start();
    }
}
